/***************************************************************************
 * Open Object Oriented ANSI C                                             *
 ***************************************************************************
 * Code given under the terms of GNU General Public Licence (GPLv3)        *
 * and without any waranties of any kind including but not limitative to   *
 * waranties on merchandability or any particular applications fitness.    *
 * For more information on GNU/GPL go on :                                 *
 * "http://www.gnu.org/copyleft/gpl.html"                                  *
 *                                                                         *
 * You are allowed to use it for any purposes in the terms of GNU/GPLv3    *
 * (or more).                                                              *
 * This text MUST stay in state on copyed sources (or sources using it)    *
 * and must not be altered.                                                *
 * You are allowed to add your name at the end of the Copylefs list.       *
 ***************************************************************************
 * Copylefts List :                                                        *
 ***************************************************************************
 * 2010-04-16 Patrick PIGNOL <pignol_patrick@hotmail.com> (Original)       *
 * (Type your name here if needed)                                         *
 ***************************************************************************/
#ifndef LIST_H
#define LIST_H

#define LIST_TYPEID 9

typedef struct List List;
typedef struct ListVirtualTable ListVirtualTable;

#include "Class.h"

struct ListVirtualTable
{
    unsigned long int TypeID;
    ClassInterface* Interface;
    ClassVirtualTable* AncestorTable;
    unsigned long int ReferenceCount;
    List* (*new)(unsigned long int pArgsCount, va_list* pParameters);
    ListVirtualTable* (*Initialize)(List* this, unsigned long int pArgsCount, va_list* pParameters);
    void (*Garbage)(List* this);
    unsigned long int (*TypeOf)(List* this);
    bool (*IsSameTypeThanTypeID)(List* this, unsigned long int pTypeID);
    bool (*IsKindOfTypeID)(List* this, unsigned long int pTypeID);
    bool (*IsSameTypeThan)(List* this, Class* pSource);
    bool (*IsKindOf)(List* this, Class* pSource);
};

struct List
{
    ListVirtualTable* VirtualTable;
    void (*Constructor)(List* this, unsigned long int pArgsCount, va_list* pParameters);
    void (*Destructor)(List* this);
    List* (*Clone)(List* this);
    Class** aItems;
    unsigned long int aCount;
    void (*Add)(List* this, Class* pItem);
    void (*Insert)(List* this, Class* pItem, unsigned long int pIndex);
    void (*Remove)(List* this, unsigned long int pIndex);
    Class* (*Items)(List* this, unsigned long int pIndex);
    unsigned long int (*Count)(List* this);
    bool (*IsInList)(List* this, unsigned long int* pIndex, Class* pItem);
};

List* ListNew(unsigned long int pArgsCount, va_list* pParameters);
ListVirtualTable* ListInitialize(List* this, unsigned long int pArgsCount, va_list* pParameters);
void ListConstructor(List* this, unsigned long int pArgsCount, va_list* pParameters);
void ListDestructor(List* this);
List* ListClone(List* this);
unsigned long int aCount;
void ListAdd(List* this, Class* pItem);
void ListInsert(List* this, Class* pItem, unsigned long int pIndex);
void ListRemove(List* this, unsigned long int pIndex);
Class* ListItems(List* this, unsigned long int pIndex);
unsigned long int ListCount(List* this);
bool ListIsInList(List* this, unsigned long int* pIndex, Class* pItem);

#endif /* LIST_H */
